home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / tests / echo2 / RCS / echo2.c,v < prev   
Encoding:
Text File  |  1992-07-17  |  1.6 KB  |  102 lines

  1. head     1.2;
  2. branch   ;
  3. access   ;
  4. symbols  srv030:1.2 srv027:1.2 srv026:1.2 srv024:1.2 srv021:1.2 srv018:1.2 srv014:1.2 srv010:1.2 srv008:1.2 srv007:1.2 srv006:1.2 srv004:1.2;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.2
  10. date     92.03.23.15.11.41;  author kupfer;  state Exp;
  11. branches ;
  12. next     1.1;
  13.  
  14. 1.1
  15. date     91.12.12.22.34.23;  author kupfer;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19.  
  20. desc
  21. @Test program to echo lines typed at the keyboard, using stdio.
  22. @
  23.  
  24.  
  25. 1.2
  26. log
  27. @Add options for using the console and for shutting down instead of
  28. just exiting.
  29. @
  30. text
  31. @/* Test program to echo lines typed at the keyboard. */
  32.  
  33. #include <stdio.h>
  34. #include <string.h>
  35. #include <sys.h>
  36.  
  37. #define BUF_SIZE    1024
  38. #define USE_CONSOLE    1    /* 0 to use the inherited stdin and stdout */
  39. #define DO_SHUTDOWN    1    /* 0 to just exit */
  40.  
  41. main()
  42. {
  43.     char buf[BUF_SIZE];
  44.     FILE *inFile;
  45.     FILE *outFile;
  46.     int status = 0;
  47.  
  48. #if !USE_CONSOLE
  49.     inFile = stdin;
  50.     outFile = stdout;
  51. #else
  52.     inFile = fopen("/dev/console", "r+");
  53.     outFile = inFile;
  54.     if (inFile == NULL) {
  55.     printf("couldn't open console\n");
  56.     status = 1;
  57.     goto done;
  58.     }
  59. #endif
  60.     for (;;) {
  61.     printf("Type something: ");
  62.     fflush(stdout);
  63.     if (fgets(buf, BUF_SIZE, inFile) == NULL) {
  64.         goto done;
  65.     }
  66.     if (strcmp(buf, ".\n") == 0) {
  67.         goto done;
  68.     }
  69.     fputs(buf, outFile);
  70.     }
  71.  
  72.  done:
  73. #if DO_SHUTDOWN
  74.     (void)Sys_Shutdown(SYS_HALT|SYS_KILL_PROCESSES|SYS_WRITE_BACK, NULL);
  75. #endif
  76.     exit(status);
  77. }
  78. @
  79.  
  80.  
  81. 1.1
  82. log
  83. @Initial revision
  84. @
  85. text
  86. @d5 1
  87. d8 2
  88. d14 3
  89. d18 12
  90. d32 3
  91. a34 2
  92.     if (fgets(buf, BUF_SIZE, stdin) == NULL) {
  93.         exit(0);
  94. d37 1
  95. a37 1
  96.         exit(0);
  97. d39 1
  98. a39 1
  99.     puts(buf);
  100. d41 6
  101. @
  102.